#include "setparamsdlg.h"
#include "ui_setparamsdlg.h"
#include <QGlobalStatic>

Q_GLOBAL_STATIC(SetParamsDlg,m_instance)

SetParamsDlg::SetParamsDlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SetParamsDlg)
{
    ui->setupUi(this);

    initComboBox();

    this->setWindowFlag(Qt::FramelessWindowHint);
}

SetParamsDlg::~SetParamsDlg()
{
    delete ui;
}

SetParamsDlg *SetParamsDlg::Instance()
{
    return m_instance;
}

void SetParamsDlg::on_pushButton_ok_clicked()
{
    m_CAN_type = ui->CANType->currentData().toInt();
    m_device_index = ui->index->currentData().toInt();
    m_baundRate = ui->baundRate->currentData().toInt();
    m_CANCom = ui->CANCom->currentData().toInt();

    this->close();
}


void SetParamsDlg::on_pushButton_cancle_clicked()
{
    this->close();
}

int SetParamsDlg::GetCANType()
{
    return m_CAN_type;
}

int SetParamsDlg::GetDeviceIndex()
{
    return m_device_index;
}

int SetParamsDlg::GetBaundRate()
{
    return m_baundRate;
}

int SetParamsDlg::GetCANCom()
{
    return m_CANCom;
}

void SetParamsDlg::initComboBox()
{
    //初始化CAN卡类型
    ui->CANType->addItem("VCI_USBCAN1",3);
    ui->CANType->addItem("VCI_USBCAN2",4);
    ui->CANType->addItem("VCI_USBCAN2A",4);
    ui->CANType->addItem("VCI_USBCAN_E_U",20);
    ui->CANType->addItem("VCI_USBCAN_2E_U",21);

    //初始化设备索引
    for(int i = 0; i < 14; i++)
    {
        ui->index->addItem(QString::number(i),i);
    }

    //初始化波特率
//    ui->baundRate->addItem("10kbps",10);
//    ui->baundRate->addItem("20kbps",20);
//    ui->baundRate->addItem("40kbps",40);
//    ui->baundRate->addItem("50kbps",50);
//    ui->baundRate->addItem("80kbps",80);
//    ui->baundRate->addItem("100kbps",100);
//    ui->baundRate->addItem("125kbps",125);
//    ui->baundRate->addItem("200kbps",200);
    ui->baundRate->addItem("250kbps",250);
//    ui->baundRate->addItem("400kbps",400);
    ui->baundRate->addItem("500kbps",500);
//    ui->baundRate->addItem("666kbps",666);
//    ui->baundRate->addItem("800kbps",800);
//    ui->baundRate->addItem("1000kbps",1000);
//    ui->baundRate->addItem("33.33kbps",33);
//    ui->baundRate->addItem("66.66kbps",66);
//    ui->baundRate->addItem("83.33kbps",83);

    //初始化通道
    ui->CANCom->addItem(QString::number(0),0);
    ui->CANCom->addItem(QString::number(1),1);
}

